VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "clsXepLoaiDaoDuc"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
Private m_sMaSV As String
Private m_sMaDD As String
Private m_iHKy As Integer
Private m_sNamHoc As String

Public Property Get masv() As String
    masv = m_sMaSV
End Property

Public Property Let masv(ByVal sMaSV As String)
    m_sMaSV = sMaSV
End Property

Public Property Get madd() As String
    madd = m_sMaDD
End Property

Public Property Let madd(ByVal sMaDD As String)
    m_sMaDD = sMaDD
End Property

Public Property Get hky() As Integer
    hky = m_iHKy
End Property

Public Property Let hky(ByVal iHKy As Integer)
    m_iHKy = iHKy
End Property

Public Property Get namhoc() As String
    namhoc = m_sNamHoc
End Property

Public Property Let namhoc(ByVal sNamHoc As String)
    m_sNamHoc = sNamHoc
End Property

Public Function ThongKe(madd As String, hky As String, namhoc As String) As ADODB.Recordset
    Dim sql As String
    
   On Error GoTo ThongKe_Error

    sql = "SELECT sv.*, TenLop, TenNganh, xldd.MaDD, DiemDD, HKy, NamHoc FROM HSSV sv, XepLoaiDaoDuc xldd, DiemDaoDuc dd, Lop l, Nganh ng " & _
                                         "WHERE xldd.MaDD = " & IIf(madd <> "", "'" & madd & "'", "xldd.MaDD") & " AND " & _
                                               "HKy = " & IIf(hky <> "", hky, "HKy") & " AND " & _
                                               "NamHoc = " & IIf(namhoc <> "", "'" & namhoc & "'", "NamHoc") & " AND " & _
                                               "sv.MaSV = xldd.MaSV AND xldd.MaDD = dd.MaDD AND " & _
                                               "sv.MaLop = l.MaLop AND l.MaNganh = ng.MaNganh"
    Call OpenConnection
    ' Create a Recordset by executing an SQL statement.
    Set ThongKe = g_ObjADOConn.Execute(sql)

   On Error GoTo 0
   Exit Function
ThongKe_Error:
    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure ThongKe of Class Module clsXepLoaiDaoDuc"
End Function

'---------------------------------------------------------------------------------------
' Procedure : SelectAll
' Date      : 27/10/2011
' Purpose   : Load danh sach tat ca record cua table co trong file du lieu
'---------------------------------------------------------------------------------------
Public Function SelectAll() As ADODB.Recordset
   On Error GoTo SelectAll_Error

    Call OpenConnection
    ' Create a Recordset by executing an SQL statement.
    Set SelectAll = g_ObjADOConn.Execute("SELECT sv.MaSV, HoDem, TenSV, ddd.MaDD, DiemDD, HKy, NamHoc FROM HSSV sv, DiemDaoDuc ddd, XepLoaiDaoDuc xldd WHERE sv.MaSV = xldd.MaSV AND ddd.MaDD = xldd.MaDD GROUP BY sv.MaSV, HoDem, TenSV, ddd.MaDD, DiemDD, HKy, NamHoc")

   On Error GoTo 0
   Exit Function
SelectAll_Error:
    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure SelectAll of Class Module clsXepLoaiDaoDuc"
End Function

'---------------------------------------------------------------------------------------
' Procedure : SelectByID
' Date      : 27/10/2011
' Purpose   : Lay record cua table ung voi ma DanhMucMonHoc truyen vao
'---------------------------------------------------------------------------------------
Public Function SelectByID(ByVal masv As String, ByVal madd As String) As ADODB.Recordset
   On Error GoTo SelectByID_Error

    Call OpenConnection
    ' Create a Recordset by executing an SQL statement.
    Set SelectByID = g_ObjADOConn.Execute("SELECT sv.MaSV, HoDem, TenSV, ddd.MaDD, DiemDD, HKy, NamHoc FROM HSSV sv, DiemDaoDuc ddd, XepLoaiDaoDuc xldd WHERE sv.MaSV = xldd.MaSV AND ddd.MaDD = xldd.MaDD AND xldd.MaSV = '" & masv & "' AND xldd.MaDD = '" & madd & "'")
    
   On Error GoTo 0
   Exit Function
SelectByID_Error:
    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure SelectByID of Class Module clsXepLoaiDaoDuc"
End Function

'---------------------------------------------------------------------------------------
' Procedure : Insert
' Date      : 27/10/2011
' Purpose   : Them 1 record moi vao table trong file du lieu
'---------------------------------------------------------------------------------------
Public Function Insert(ByVal ObjXepLoaiDaoDuc As clsXepLoaiDaoDuc) As Boolean
    
   On Error GoTo Insert_Error

    Call OpenConnection
    g_ObjADOConn.Execute ("INSERT INTO XepLoaiDaoDuc(MaSV, MaDD, HKy, NamHoc) " & _
                          "VALUES('" & ObjXepLoaiDaoDuc.masv & "', '" & ObjXepLoaiDaoDuc.madd & "', '" & ObjXepLoaiDaoDuc.hky & "', '" & ObjXepLoaiDaoDuc.namhoc & "')")
    Call CloseConnection
    Insert = True
    
   On Error GoTo 0
   Exit Function
Insert_Error:
    Insert = False
    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure Insert of Class Module clsXepLoaiDaoDuc"
End Function

'---------------------------------------------------------------------------------------
' Procedure : Delete
' Date      : 27/10/2011
' Purpose   : Xoa 1 record cua table trong file du lieu
'---------------------------------------------------------------------------------------
Public Function Delete(ByVal masv As String, ByVal madd As String) As Boolean
   On Error GoTo Delete_Error

    Call OpenConnection
    g_ObjADOConn.Execute ("DELETE FROM XepLoaiDaoDuc WHERE MaSV='" & masv & "' AND MaDD='" & madd & "'")
    Call CloseConnection
    Delete = True
    
   On Error GoTo 0
   Exit Function
Delete_Error:
    Delete = False
    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure Delete of Class Module clsXepLoaiDaoDuc"
End Function
